package com.yhsimon.singleton;

public class SingletonTest8 {
    public static void main(String[] args) {
        System.out.println("枚举方式");
        Singleton instance1 = Singleton.INSTANCE;
        Singleton instance2 = Singleton.INSTANCE;
        System.out.println(instance1==instance2);
        System.out.println("instance1的哈希值"+instance1.hashCode());
        System.out.println("instance2的哈希值"+instance2.hashCode());

        instance1.sayHello();
    }
}

//使用枚举，可以实现单例，推荐
enum Singleton{
    INSTANCE;
    public void sayHello(){
        System.out.println("hello!");
    }
}